import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * User:xieChao
 * Date:2022/10/15 21:22
 */
public class ShellSort {
    public static void shellSort(int[] array,int gap){
        for (int i = gap; i < array.length; i++) {
            int tmp = array[i];
            int j = i-gap;
            for(;j>=0;j-=gap){
                if(array[j] > tmp){
                    array[j+gap] = array[j];
                }else{
                    break;
                }
            }
            array[j+gap] = tmp;
        }
    }
    public static void main(String[] args) {
        int[] array = {13,7,8,3,23,12,14,5,9};
        int gap = array.length;
        while(gap>1){
            shellSort(array,gap);
            gap /= 2;
        }
        shellSort(array,1);
        System.out.println(Arrays.toString(array));
    }
}
